package com.qf.bbapi.controller;

import com.qf.bbapi.dto.*;
import com.qf.bbapi.service.intf.UserService;
import com.qf.bbapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/user/")
@Api(tags = "用户相关操作接口")
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("checkPhone.do")
    @ApiOperation(value = "检查手机号")
    public R checkPhone(String phone){
        return userService.checkPhone(phone);
    }
    @PostMapping("passLogin.do")
    @ApiOperation(value = "手机号密码登录")
    public R passLogin(@RequestBody UserPasswordLoginDto userPasswordLoginDto){
        return userService.loginPassword(userPasswordLoginDto);
    }
    @PostMapping("codeLogin.do")
    @ApiOperation(value = "手机号验证码登录")
    public R codeLogin(@RequestBody UserCodeLoginDto userCodeLoginDto){
        return userService.loginCode(userCodeLoginDto);
    }
    @PostMapping("findPassword.do")
    @ApiOperation(value = "找回密码")
    public R findPassWord(@RequestBody UserFindDto userFindDto){
        return userService.findPassword(userFindDto);
    }
    @GetMapping("loginOut.do")
    @ApiOperation(value = "退出登录")
    public R loginOut(HttpServletRequest request){
//        System.out.println(request.getIntHeader("token"));
        return userService.loginOut(request.getIntHeader("token"));
    }
    @PostMapping("regist.do")
    @ApiOperation(value = "添加用户")
    public R regist(@RequestBody UserAddDto userAddDto){
        return userService.regist(userAddDto);
    }

    @ApiOperation("修改个人信息")
    @PostMapping("updateData.do")
    public R updateData(@RequestBody UserDataDto dto,HttpServletRequest request){
        return userService.updateData(dto,request.getIntHeader("token"));
    }

    @ApiOperation("显示个人数据")
    @GetMapping("selectOne.do")
    public R selectOne(HttpServletRequest request){
        return userService.selectOne(request.getIntHeader("token"));
    }
}
